import {
    Controller,
    Get,
    Post,
    Body,
    Patch,
    Param,
    Delete,
} from '@nestjs/common';
import { BooksService } from './books.service';
import { CreateBookDto } from './dto/create-book.dto';
import { UpdateBookDto } from './dto/update-book.dto';
import { ApiOperation } from '@nestjs/swagger';

@Controller('books')
export class BooksController {
    constructor(private readonly booksService: BooksService) {}

    @ApiOperation({ summary: '书籍添加' })
    @Post()
    create(@Body() createBookDto: CreateBookDto) {
        return this.booksService.create(createBookDto);
    }

    @ApiOperation({ summary: '书籍数量统计' })
    @Get()
    statisticsTotal() {
        return this.booksService.statisticsTotal();
    }
    @ApiOperation({ summary: '书籍查询' })
    @Get(':id')
    findBook(@Param('id') id: string) {
        return this.booksService.findBook(+id);
    }

    @Patch(':id')
    update(@Param('id') id: string, @Body() updateBookDto: UpdateBookDto) {
        return this.booksService.update(+id, updateBookDto);
    }

    @Delete(':id')
    remove(@Param('id') id: string) {
        return this.booksService.remove(+id);
    }
}
